From b9f54c5524400681366420263a8b7bd1f6492074 Mon Sep 17 00:00:00 2001 From: Richard Diamond Date: Tue, 11 Nov 2014 14:51:27 -0600 Subject: [PATCH] Don't count custom compile scripts as targets. --- src/cargo/util/toml.rs | 4 +++- tests/test_cargo_compile_custom_build.rs | 16 ++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/cargo/util/toml.rs b/src/cargo/util/toml.rs index ead2c4f59..ffdaf9b8a 100644 --- a/src/cargo/util/toml.rs +++ b/src/cargo/util/toml.rs @@ -118,7 +118,9 @@ pub fn to_manifest(contents: &[u8], Some(ref toml) => add_unused_keys(&mut manifest, toml, "".to_string()), None => {} } - if manifest.get_targets().len() == 0 { + if manifest.get_targets().iter() + .filter(|t| !t.get_profile().is_custom_build() ) + .next().is_none() { return Err(human(format!("either a [lib] or [[bin]] section must \ be present"))) } diff --git a/tests/test_cargo_compile_custom_build.rs b/tests/test_cargo_compile_custom_build.rs index cd441d049..056234ddd 100644 --- a/tests/test_cargo_compile_custom_build.rs +++ b/tests/test_cargo_compile_custom_build.rs @@ -837,3 +837,19 @@ test!(release_with_build_script { assert_that(p.cargo_process("build").arg("-v").arg("--release"), execs().with_status(0)); }) + +test!(build_script_only { + let p = project("foo") + .file("Cargo.toml", r#" + [project] + name = "foo" + version = "0.0.0" + authors = [] + build = "build.rs" + "#) + .file("build.rs", r#"fn main() {}"#); + assert_that(p.cargo_process("build").arg("-v"), + execs().with_status(101) + .with_stderr("either a [lib] or [[bin]] section must \ + be present")); +}) -- 2.30.2